package danceDoll;

import com.jme3.animation.AnimControl;
import com.jme3.animation.Skeleton;
import com.jme3.asset.AssetManager;
import com.jme3.scene.Node;
import com.jme3.scene.debug.SkeletonDebugger;

/**
 * Read a Model from the AssetManager and attach it to the Node.
 * @author Vincent Bosche
 * @verion 1.0
 */
public class Model {

    private AssetManager assetManager;
    private SkeletonDebugger skeletonDebug;
    private Node root, doll;
    
    public Model(AssetManager assetManager) {
        this.assetManager = assetManager;
        root = new Node("Root Node");
    }

    /**
     * Loads the Model Sto from the AssetManager, creates the SkeletonDebuuger and returns the Node.
     * @return Node with the Model
     */
    public Node getModel() {

        doll = (Node) assetManager.loadModel("Models/Stu_NEW/stu_NEW8.j3o");
        skeletonDebug = new SkeletonDebugger("skeleton", getSkeletton());

        doll.setLocalScale(0.04f);
        root.attachChild(doll);
 
        root.setLocalTranslation(0.5f, 0f, -0.6f);
        
        return root;
    }

    /**
     * Returns the Node where the Model ist attached.
     * @return Node with the Model
     */
    public Node getModelNode() {
        return root;
    }

    /**
     * Returns the Skeleton from the AnimControl from the Model
     * @return skeleton from the model
     */
    public Skeleton getSkeletton() {
        AnimControl ctl = (AnimControl) doll.getControl(0);
        return ctl.getSkeleton();
    }
    
    /**
     * Returns the SkeletonDebugger from the Model
     * @return the SkeletonDebugger
     */
    public SkeletonDebugger skeletonDebug() {
        return skeletonDebug;
    } 
}
